<?php
session_start();
header("Content-type:text/html; charset=utf-8");
$mysqli = new mysqli('localhost:3306','root','','boke');
// $mysqli = new mysqli('localhost:3306','liuboyto_root','#MySQLmima#618','liuboyto_618');

mysqli_query($mysqli,"set names utf8");

// echo $index;
// 页面列表个数
$pagesize= 2;
$index=$_POST["indexof"];
// 点击第几个按钮
$j =$_POST["j"];
// 页码

// echo $j;
if(0<$index&&$index<=$j){
$sql = "select * from wenzhang where userid=1 limit ".($index-1)*$pagesize.",".$pagesize;

$_SESSION["page"]=$index;

$res = $mysqli->query($sql);
while ($row = $res->fetch_assoc()) {
	$b[]=$row;
// // print_r($row);
}
echo json_encode($b);

}elseif($index==0){
	if($_SESSION["page"]==1){
		$_SESSION["page"]=2;
	}
	$sql1 = "select * from wenzhang where userid=1 limit ".($_SESSION["page"]-2)*$pagesize.",".$pagesize;
	$res1 = $mysqli->query($sql1);
while ($row1 = $res1->fetch_assoc()) {
	$b1[]=$row1;
// // print_r($row);
}
echo json_encode($b1);
$_SESSION["page"]=$_SESSION["page"]-1;
if($_SESSION["page"]<1){
	$_SESSION["page"]=1;
};
// echo $_SESSION["page"];
}else{
	
	$sql2 = "select * from wenzhang where userid=1 limit ".($_SESSION["page"])*$pagesize.",".$pagesize;
	$res2 = $mysqli->query($sql2);
while ($row2 = $res2->fetch_assoc()) {
	$b2[]=$row2;
// // print_r($row);
}
echo json_encode($b2);
$_SESSION["page"]=$_SESSION["page"]+1;
if($_SESSION["page"]>$j-1){
	$_SESSION["page"]=$j;
	// intval()取整
};
// echo $_SESSION["page"];
}

$mysqli->close();

?>